Developer Documentation

QuickTime 4 API Documentation

3D Graphics Programming with QuickDraw 3D 1.5.4

Previous | QD3D Book | Overview | Chapter Contents | Next |

Hit Sorting

In some cases, you can have QuickDraw 3D sort a hit list before returning it to your application. The sorting is based on either increasing or decreasing distance from some point, the pick origin. As a result, hit-list sorting is possible only when the pick geometry has a clearly defined pick origin. Pick objects whose pick geometries have a pick origin are called metric pick objects (or metric picks ). Window-point picking uses metric pick objects. With window-rectangle pick objects, however, there is no clearly defined pick origin. As a result, window-rectangle pick objects are not metric: you cannot have the hit list sorted by distance.

With a metric pick, distances are measured along the ray from the pick origin to the point of intersection on the picked object. If that ray intersects a picked object more than once, QuickDraw 3D always returns the hit that's closest to the pick origin.

Recall that you can have QuickDraw 3D put either entire objects or parts of objects into a hit list. When you are hit-testing parts of objects--vertices, edges, and faces--you need to keep in mind that the tolerance values can complicate the process of calculating distances (and hence the process of sorting hits). For example, a window point might be equally distant from both a vertex and an edge, at least within the tolerance values associated with the window-point pick object. To establish a unique sorting order in such cases, QuickDraw 3D gives priority to vertices, then to edges, and finally to faces.

Note that the distances used to establish a sort order might not be the same distances reported to your application when you retrieve hit information. Consider, for example, the situation illustrated in Figure 5 . Here, the vertex V is within the current vertex tolerance of the window point pick object and therefore qualifies as a hit. QuickDraw 3D uses the distance d' from the pick origin to the closest point on the pick ray (that is, V' ) as the basis for sorting vertex V in the hit list. However, when reporting the distance from the pick origin to the picked vertex V , QuickDraw 3D gives the actual distance d .

Figure 5 Determining a vertex sorting distance

QuickDraw 3D calculates distances to edges and faces in an analogous manner. If the pick ray passes within the current edge tolerance of an edge, the sorting distance is set to the distance d' from the pick ray origin to the projection onto the pick ray of the point on the edge that is closest to the pick ray. See Figure 6 .

Figure 6 Determining an edge sorting distance

If the pick ray intersects a face, the sorting distance is set to the distance from the pick ray origin to the projection onto the pick ray of the face vertex that is closest to the pick ray. See Figure 7 .

Figure 7 Determining a face sorting distance

The sorting distance d' is not always less than the actual distance d to the hit object. In Figure 7 , for example, d' is greater than d .


© 1997 Apple Computer, Inc.

Previous | QD3D Book | Overview | Chapter Contents | Next |